package com.zhaokuner.ctrl;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.domain.AlipayDataDataserviceBillDownloadurlQueryModel;
import com.alipay.api.request.AlipayDataDataserviceBillDownloadurlQueryRequest;
import com.alipay.api.response.AlipayDataDataserviceBillDownloadurlQueryResponse;
import com.alipay.config.AlipayConfig;

@Controller
@RequestMapping("/tt")
public class DownloadCtrl {

	@RequestMapping("alipay/down")
	@ResponseBody
	public Object query(HttpServletRequest request, HttpServletResponse response, String out_trade_no, String trade_no) throws AlipayApiException {

		AlipayClient client = new DefaultAlipayClient(AlipayConfig.URL, AlipayConfig.APPID, AlipayConfig.RSA_PRIVATE_KEY, AlipayConfig.FORMAT, AlipayConfig.CHARSET, AlipayConfig.ALIPAY_PUBLIC_KEY, AlipayConfig.SIGNTYPE);
		AlipayDataDataserviceBillDownloadurlQueryRequest alipay_request = new AlipayDataDataserviceBillDownloadurlQueryRequest();

		AlipayDataDataserviceBillDownloadurlQueryModel model = new AlipayDataDataserviceBillDownloadurlQueryModel();
		model.setBillType("trade");
		model.setBillDate("2017-11-01");
		alipay_request.setBizModel(model);

		AlipayDataDataserviceBillDownloadurlQueryResponse alipay_response = client.execute(alipay_request);
		System.out.println(alipay_response.getBillDownloadUrl());
		return alipay_response.getBillDownloadUrl();
	}

}
